package com.zzyl.nursing.controller.member;


import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.utils.UserThreadLocal;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.dto.ReservationPageDto;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.nursing.vo.CountByTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
@RequiredArgsConstructor
public class MemberReservationController extends BaseController {

    private final IReservationService reservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Integer count = reservationService.getCancelledReservationCount();
        return R.ok(count);
    }

    @GetMapping("countByTime")
    public R<List<CountByTimeVo>> countByTime(Long time) {
        return R.ok(reservationService.countByTime(time));
    }

    @PostMapping
    public R<Void> saveReservation(@RequestBody ReservationDto reservationDto) {
        reservationService.saveReservation(reservationDto);
        return R.ok();
    }

    @GetMapping("page")
    public R<TableDataInfo<Reservation>> reservationPage(ReservationPageDto reservationDto) {
        startPage();
        List<Reservation> list = reservationService.reservationPage(reservationDto);
        return R.ok(getDataTable(list));
    }

    @PutMapping("{id}/cancel")
    public R<Object> cancelReservation(@PathVariable Long id) {
        reservationService.cancelReservation(id);
        return R.ok();
    }
}
